﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Ryder_US_Website.BUS;
using Ryder_US_Website.Utils;

namespace Ryder_US_Website.Presentation.Admin
{
    public partial class User_Insert : System.Web.UI.Page
    {
        RUS_User curUser = new RUS_User();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["RUS_User"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            curUser = (RUS_User)Session["RUS_User"];
            if (curUser.User_role != 0)
            {
                Response.Redirect("Home.aspx");
            }
        }
        protected void btnLamLai_Click(object sender, EventArgs e)
        {
            clean();
        }
        protected void clean()
        {
            rbQuanTri.Checked=true;
            txtTenDangNhap.Text = "";
            txtMatKhau.Text = "";
        }
        protected bool isPassword(String str1, String str2)
        {
            if (str1.Length != str2.Length)
                return false;
            for (int i = 0; i < str1.Length; i++)
            {
                if (str1[0] != str2[0])
                    return false;
            }
            return true;
                
        }
        protected void btnHuy_Click(object sender, EventArgs e)
        {
            Response.Redirect("User_List.aspx");
        }

        protected void btnLamLai_Click1(object sender, EventArgs e)
        {
            clean();
        }

        protected void btnThem_Click1(object sender, EventArgs e)
        {
            try
            {
                RUS_User user = new RUS_User();
                user.User_username = txtTenDangNhap.Text;
                user.User_password = txtMatKhau.Text;
                user.User_role = (rbQuanTri.Checked == true) ? 0 : 1;
                UserBUS.Insert(user.User_username, user.User_password, user.User_role);
                Response.Write(UtilHelpers.ShowMessage("Thêm thành công"));
                Response.Redirect("User_List.aspx");
            }
            catch(Exception ex)
            {
                Response.Write(UtilHelpers.ShowMessage(ex.Message));

            }
        }
                      
    }
}
